package service

import (
	"encoding/json"
	"sdn-executor/storage/sql/executor"
	"sdn-executor/utils/erros"

	"sdn-executor/core/engine"
	"sdn-executor/model/common"
)

func createSdnExecutorResult(query any, baseQuery *common.BaseQuery, m *engine.Message) *erros.Error {
	strRequest, _ := json.Marshal(query)
	dbResult := executor.SdnExecutorResult{
		Device:      baseQuery.Device,
		Status:      string(common.ExecStatusWaitExec),
		Sequence:    0,
		RequestId:   m.RequestId,
		RequestType: string(m.Type),
		Channel:     baseQuery.Channel,
		Priority:    baseQuery.Priority,
		User:        baseQuery.User,
		Caller:      baseQuery.Caller,
		ReadOnly:    baseQuery.ReadOnly,
		Request:     string(strRequest),
		Result:      "",
	}

	return executor.CreateSdnExecutorResult(&dbResult)
}
